package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Register;
import com.neuedu.his.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    RegisterService service;

    @RequestMapping("/add")
    public Boolean add(@RequestBody Register r){
        r.setRegisttime(new Date());
        r.setVisitstate(1);
        return service.save(r);
    }

    @RequestMapping("/getbyuserid")
    public Map<String, List<Register>> getbyuserid(@RequestParam Integer id){
        QueryWrapper<Register> unprocessedqw=new QueryWrapper<>();
        unprocessedqw.eq("userid",id).eq("visitstate",1);
        List<Register> unprocessedList=service.list(unprocessedqw);
        QueryWrapper<Register> processedqw=new QueryWrapper<>();
        processedqw.eq("userid",id).eq("visitstate",2);
        List<Register> processedList=service.list(processedqw);

        // 封装结果
        Map<String, List<Register>> result = new HashMap<>();
        result.put("unprocessedPatients", unprocessedList);
        result.put("processedPatients", processedList);

        return result;
    }

    @RequestMapping("/getbydeptid")
    public Map<String, List<Register>> getbydeptid(@RequestParam Integer id){
        QueryWrapper<Register> unprocessedqw=new QueryWrapper<>();
        unprocessedqw.eq("deptid",id).eq("visitstate",1);
        List<Register> unprocessedList=service.list(unprocessedqw);
        QueryWrapper<Register> processedqw=new QueryWrapper<>();
        processedqw.eq("deptid",id).in("visitstate",2,3);
        List<Register> processedList=service.list(processedqw);

        // 封装结果
        Map<String, List<Register>> result = new HashMap<>();
        result.put("unprocessedPatients", unprocessedList);
        result.put("processedPatients", processedList);

        return result;
    }
}
